package com.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mapper.WorksMapper;
import com.model.Works;
import com.util.PageBean;
@Service
public class WorksServiceImpl implements WorksService{
        
	@Autowired
	private WorksMapper worksMapper;

	//查询多条记录
	public List<Works> queryWorksList(Works works,PageBean page) throws Exception {
		Map<String, Object> map =getQueryMap(works, page);
		
		List<Works> getWorks = worksMapper.query(map);
		
		return getWorks;
	}
	
	//得到记录总数
	@Override
	public int getCount(Works works) {
		Map<String, Object> map = getQueryMap(works, null);
		int count = worksMapper.getCount(map);
		return count;
	}
	
	private Map<String, Object> getQueryMap(Works works,PageBean page){
		Map<String, Object> map = new HashMap<String, Object>();
		if(works!=null){
			map.put("wid", works.getWid());
			map.put("tid", works.getTid());
			map.put("wtitle", works.getWtitle());
			map.put("wdate", works.getWdate());
			map.put("address", works.getAddress());
			map.put("wmemo", works.getWmemo());
			map.put("wprice", works.getWprice());
			map.put("sno", works.getSno());
			map.put("atime", works.getAtime());
			map.put("flag", works.getFlag());
			map.put("lo", works.getLo());
			map.put("la", works.getLa());
			map.put("sort", works.getSort());
			map.put("condition", works.getCondition());

		}
		PageBean.setPageMap(map, page);
		return map;
	}
		
	//添加
	public int insertWorks(Works works) throws Exception {
		return worksMapper.insertWorks(works);
	}

	//根据ID删除
	public int deleteWorks(int id) throws Exception {
		return worksMapper.deleteWorks(id);
	}

	//更新
	public int updateWorks(Works works) throws Exception {
		return worksMapper.updateWorks(works);
	}
	
	//根据ID得到对应的记录
	public Works queryWorksById(int id) throws Exception {
		Works po =  worksMapper.queryWorksById(id);
		return po;
	}
}

